﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TFXK.Common;
using log4net;
using TFXK.BLL;
using TFXK.Model;

public partial class Regster : System.Web.UI.Page
{
    private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    private static readonly CustomsBLL bllCustoms = new CustomsBLL();

    public string pro = "''";
    public string cty = "''";
    public string area = "''";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string province = StringUtil.HtmlEncode(Request.Form["province"] + "");
        string city = StringUtil.HtmlEncode(Request.Form["city"] + "");
        string area = StringUtil.HtmlEncode(Request.Form["area"] + "");
        string uname = StringUtil.HtmlEncode(txtUserName.Value + "");
        string upass = StringUtil.HtmlEncode(this.txtPass.Value);
        string trueName = StringUtil.HtmlEncode(this.txtTrueName.Value);
        string phone = StringUtil.HtmlEncode(this.txtPhone.Value);
        string email = StringUtil.HtmlEncode(this.txtEmail.Value);

        string gender = "";
        string send_url = "";
        string send_url_result = "";

        if (uname.Length > 0 && upass.Length > 0 && trueName.Length > 0)
        {
            if (bllCustoms.ExistsName(uname))
            {
                Msg.Show("用户名已存在！");
            }
            else
            {
                Customs temp = new Customs();
                temp.loginName = uname;
                temp.loginPass = upass;
                temp.trueName = trueName;
                if (province.Contains("选择"))
                {
                    temp.userCity = "";
                }
                else
                {
                    temp.userCity = province + "-" + city + "-" + area;
                }
                temp.userEmail = email;
                temp.userPhone = phone;
                temp.userSex = rbtBoy.Checked ? 0 : 1;
                temp.userState = 0;
                temp.userTel = "";
                int row = bllCustoms.Add(temp);
                temp.id = row;


                //added on 6/8/2011
                if (temp.userSex == 0)
                {
                    gender = "男";
                }
                else if (temp.userSex == 1)
                {
                    gender = "女";
                }

                send_url = "http://mb345.com:999/WS/Send.aspx?CorpID=LKSDK0000834&Pwd=930883&Mobile=13550047845&Content=" + HttpUtility.UrlEncode(temp.trueName + " " + gender + " " + temp.userCity + " " + temp.userPhone + " 刚刚注册了帐号，请尽快审核!", System.Text.Encoding.GetEncoding("GB2312"));
                
                if (row > 0)
                {
                    try
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "xyzlvyou@hotmail.com", "网站新注册用户", "邮件新注册请尽快审核！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！", "");
                        send_url_result = new System.Net.WebClient().DownloadString(send_url);
                    }
                    catch{
                     
                    }
                   // Session["UserLogin"] = temp;

                    if (send_url_result.Equals("0"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 发送短信成功", "");
                    }
                    else if (send_url_result.Equals("-1"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 由于 帐号未注册 发送短信失败", "");
                    }
                    else if (send_url_result.Equals("-2"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 由于 其他错误 发送短信失败", "");
                    }
                    else if (send_url_result.Equals("-3"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 由于 密码错误 发送短信失败", "");
                    }
                    else if (send_url_result.Equals("-4"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 由于 手机号格式不对 发送短信失败", "");
                    }
                    else if (send_url_result.Equals("-5"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 由于 余额不足 发送短信失败", "");
                    }
                    else if (send_url_result.Equals("-6"))
                    {
                        Common.NetMailSend("smtp.sina.cn", "innly@sina.cn", "123456789", "下驿栈-阿林", "1429997436@qq.com", "网站新注册用户", "网站新注册用户发送短信失败！", "网站新用户：" + temp.trueName + "已成功注册,请登录网站后台审核！ 由于 定时发送时间不是有效的时间格式 发送短信失败", "");
                    }


                    if (!string.IsNullOrEmpty(Session["myurl"] + ""))
                    {
                        Response.Write("<script>alert('注册成功!');window.parent.location='" + Session["myurl"] + "'</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('注册成功!');window.parent.location='MyTravel.aspx'</script>");

                    }
                }
                else {
                    Msg.Show("注册失败!稍后重试!");
                }
            }
        }
        else
        {
            Msg.Show("信息输入不完整！");
        }
        
    }
}
